package reflect;

import java.util.Scanner;

/**
 * 输入任意一个类，如果该类被注解@AutorunClass标注了，则实例化对象,没有被标注，则提示
 * 1.输入reflect.Person   -------------------->实例化对象
 * 2.输入reflect.Student ------------------>提示该类没有被注解
 */
public class Test2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名：");
        String className = scan.next();
        Class cls = Class.forName(className);
        if (cls.isAnnotationPresent(AutorunClass.class)){
            System.out.println("实例化"+className);
            Object obj = cls.newInstance();
            System.out.println(obj);
        }else{
            System.out.println(className+"没有被标注");
        }
    }

}
